from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By
#创建一个浏览器实例
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")

#查找页面左上边栏更多
#<a href="http://www.baidu.com/more/" name="tj_briicon" class="s-bri c-font-normal c-color-t" target="_blank">更多</a>
gengduo = driver.find_element(By.NAME,"tj_briicon")
#<a class="" href="https://baike.baidu.com" target="_blank" name="tj_baike"><img src="https://pss.bdstatic.com/static/superman/img/topnav/newbaike-889054f349.png"><div class="s-top-more-title c-font-normal c-color-t">百科</div></a>
baike = driver.find_element(By.NAME,"tj_baike")
ac = ActionChains(driver)
ac.move_to_element(gengduo).move_to_element(baike).click().perform()
sleep(1)
#切换至百度百科界面
driver.switch_to.window(driver.window_handles[1])
sleep(2)
#查找搜索框
#<input class="searchInput" autocomplete="off" autocorrect="off" value="">
driver.find_element(By.CLASS_NAME,"searchInput").send_keys("玄奘")
sleep(2)
#点击搜索
#键盘操作导入keys，输入回车
ac.send_keys(Keys.ENTER).perform()
sleep(2)
#移动至导航栏点击百科团队
#<dl class="index-module_team__Heqwh"><dt><a class="" href="#">百科团队</a></dt><dd><div class="index-module_navBarItem__m7wZ4"><a href="/campus" target="_blank">校园团</a></div><div class="index-module_navBarItem__m7wZ4"><a href="https://baike.baidu.com/talent/home/index" target="_blank">分类达人团</a></div><div class="index-module_navBarItem__m7wZ4"><a href="/item/百科热词团队" target="_blank">热词团</a></div><div class="index-module_navBarItem__m7wZ4"><a href="/tashuo/browse/content?id=8ebf3bd36116a39085e0da29" target="_blank">繁星团</a></div><div class="index-module_navBarItem__m7wZ4"><a href="/kedou/" target="_blank">蝌蚪团</a></div></dd></dl>
driver.find_element(By.CLASS_NAME,"index-module_team__Heqwh").click()
sleep(3)
#等待一下下拉栏出现，定位分类达人团点击
#<a href="https://baike.baidu.com/talent/home/index" target="_blank">分类达人团</a>
driver.find_element(By.LINK_TEXT,"分类达人团").click()
sleep(2)
driver.switch_to.window(driver.window_handles[1])
sleep(2)
#回退
driver.back()
driver.back()
sleep(10)
#前进
driver.forward()
sleep(5)
#切换窗口
driver.switch_to.window(driver.window_handles[0])
sleep(3)







